﻿using System;
using System.Windows;

using Microsoft.Shell;

namespace Hetymine.Executioner {
    public static class Entry {
        private const string Unique = "Hetymine.Executioner--AF34D9";

        [STAThread]
        public static void Main() {
            if (SingleInstance<App>.InitializeAsFirstInstance(Unique)) {                
                var application = new App();
                application.InitializeComponent();

                // Since we don't want the command box to be the main window,
                // but still need a window handle for registering hotkeys hooking
                //  messages, we use a dummy window
                application.MainWindow = new Window();
                application.MainWindow.Loaded += (o, e) => {
                    application.MainWindow.Hide();

                    // Initialize executioner
                    Executioner.Initialize();                    
                };
                
                application.MainWindow.ShowInTaskbar = false;
                // Position it off screen so the user won't see it flash open and then hide
                application.MainWindow.Left = -300;
                application.MainWindow.Top = -300;
                application.MainWindow.Width = 0;
                application.MainWindow.Height = 0;
                application.MainWindow.Show();

                application.Run();

                // Allow single instance code to perform cleanup operations
                SingleInstance<App>.Cleanup();
            }
        }
    }
}
